home *** CD-ROM | disk | FTP | other *** search
/ PCMania 56 / PCMania CD56_1.iso / abc.z / NETWORK.FRM < prev    next >
Text File  |  1996-12-16  |  16KB  |  564 lines

  1. VERSION 4.00
  2. Begin VB.Form NetworkDatabaseDemo 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Network Database Demo"
  7.    ClientHeight    =   1950
  8.    ClientLeft      =   1245
  9.    ClientTop       =   2190
  10.    ClientWidth     =   5265
  11.    ClipControls    =   0   'False
  12.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  13.       Name            =   "MS Sans Serif"
  14.       Size            =   8.25
  15.       Charset         =   0
  16.       Weight          =   700
  17.       Underline       =   0   'False
  18.       Italic          =   0   'False
  19.       Strikethrough   =   0   'False
  20.    EndProperty
  21.    ForeColor       =   &H80000008&
  22.    Height          =   2355
  23.    Icon            =   "NETWORK.frx":0000
  24.    Left            =   1185
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    ScaleHeight     =   1950
  28.    ScaleWidth      =   5265
  29.    Top             =   1845
  30.    Width           =   5385
  31.    Begin VB.CommandButton BrowseBtn 
  32.       Appearance      =   0  'Flat
  33.       BackColor       =   &H80000005&
  34.       Caption         =   "&Browse..."
  35.       Height          =   375
  36.       Left            =   3690
  37.       TabIndex        =   6
  38.       Top             =   795
  39.       Width           =   1335
  40.    End
  41.    Begin VB.PictureBox Picture1 
  42.       Appearance      =   0  'Flat
  43.       BackColor       =   &H00C0C0C0&
  44.       BorderStyle     =   0  'None
  45.       ForeColor       =   &H80000008&
  46.       Height          =   495
  47.       Left            =   4350
  48.       Picture         =   "NETWORK.frx":030A
  49.       ScaleHeight     =   495
  50.       ScaleWidth      =   495
  51.       TabIndex        =   4
  52.       Top             =   195
  53.       Width           =   495
  54.    End
  55.    Begin VB.Data Data1 
  56.       Appearance      =   0  'Flat
  57.       Caption         =   "Data1"
  58.       Connect         =   ""
  59.       DatabaseName    =   ""
  60.       Exclusive       =   0   'False
  61.       Height          =   270
  62.       Left            =   1440
  63.       Options         =   0
  64.       ReadOnly        =   0   'False
  65.       RecordsetType   =   1  'Dynaset
  66.       RecordSource    =   "Network"
  67.       Top             =   3600
  68.       Visible         =   0   'False
  69.       Width           =   1935
  70.    End
  71.    Begin VB.CommandButton cmdCancel 
  72.       Appearance      =   0  'Flat
  73.       BackColor       =   &H80000005&
  74.       Caption         =   "&Cancel"
  75.       Height          =   375
  76.       Left            =   2640
  77.       TabIndex        =   2
  78.       Top             =   1440
  79.       Width           =   1335
  80.    End
  81.    Begin VB.CommandButton cmdOK 
  82.       Appearance      =   0  'Flat
  83.       BackColor       =   &H80000005&
  84.       Caption         =   "&OK"
  85.       Default         =   -1  'True
  86.       Height          =   375
  87.       Left            =   1065
  88.       TabIndex        =   1
  89.       Top             =   1440
  90.       Width           =   1335
  91.    End
  92.    Begin VB.TextBox Text1 
  93.       Appearance      =   0  'Flat
  94.       Height          =   285
  95.       Left            =   105
  96.       TabIndex        =   0
  97.       Top             =   840
  98.       Width           =   3465
  99.    End
  100.    Begin MSComDlg.CommonDialog OpenDatabaseFile 
  101.       Left            =   120
  102.       Top             =   1440
  103.       _Version        =   65536
  104.       _ExtentX        =   847
  105.       _ExtentY        =   847
  106.       _StockProps     =   0
  107.    End
  108.    Begin AbcflowLib.ABC ABC1 
  109.       Left            =   4320
  110.       Top             =   1440
  111.       _Version        =   65536
  112.       _ExtentX        =   1085
  113.       _ExtentY        =   873
  114.       _StockProps     =   1
  115.    End
  116.    Begin VB.Label Label2 
  117.       Alignment       =   2  'Center
  118.       Appearance      =   0  'Flat
  119.       BackColor       =   &H00C0C0C0&
  120.       BackStyle       =   0  'Transparent
  121.       Caption         =   "Press ""Browse"" to choose another database."
  122.       ForeColor       =   &H80000008&
  123.       Height          =   495
  124.       Left            =   840
  125.       TabIndex        =   5
  126.       Top             =   120
  127.       Width           =   3015
  128.    End
  129.    Begin VB.Label Label1 
  130.       Appearance      =   0  'Flat
  131.       AutoSize        =   -1  'True
  132.       BackColor       =   &H00C0C0C0&
  133.       Caption         =   "Database File:"
  134.       ForeColor       =   &H80000008&
  135.       Height          =   195
  136.       Left            =   120
  137.       TabIndex        =   3
  138.       Top             =   600
  139.       Width           =   1245
  140.    End
  141.    Begin VB.Line Line1 
  142.       BorderColor     =   &H00FFFFFF&
  143.       X1              =   0
  144.       X2              =   5280
  145.       Y1              =   1320
  146.       Y2              =   1320
  147.    End
  148. End
  149. Attribute VB_Name = "NetworkDatabaseDemo"
  150. Attribute VB_Creatable = False
  151. Attribute VB_Exposed = False
  152. Option Explicit
  153.     
  154.     Dim ABC As Object
  155.     Dim NetSource As RECORD
  156.     Dim UserName As String
  157.     Dim DataBaseFile As String
  158.     Dim TestFileValid As String
  159.  
  160.     Const DATA_ERRCONTINUE = 1
  161.     Const DATA_ERRDISPLAY = 0
  162.     Const OFN_FILEMUSTEXIST = &H1000&
  163.     Const OFN_PATHMUSTEXIST = &H800&
  164.  
  165.     
  166.  
  167. Private Sub ABC1_AppQuitNOTIFY()
  168.     Data1.Recordset.Close
  169.     End
  170. End Sub
  171.  
  172. Private Sub ABC1_DoubleClickSUBCLASS(ByVal Object As Object, ByVal Chart As Object, Override As Boolean)
  173.     Dim Obj As Object
  174.     
  175.     Set Obj = ABC1.Chart.Objects.ItemFromText(".mdb")
  176.  
  177.     If Obj.Valid Then
  178.         ' Get the database from the chart
  179.         Data1.DatabaseName = Obj.Text
  180.         GetDatabaseInfo (Object.Text)
  181.     Else
  182.         
  183.     End If
  184.     Override = True
  185.  
  186. End Sub
  187.  
  188. Private Sub BrowseBtn_Click()
  189.     'In case of error
  190.     On Error Resume Next
  191.  
  192.     'Set properties here
  193.     OpenDatabaseFile.CancelError = True
  194.     OpenDatabaseFile.DefaultExt = "mdb"
  195.     OpenDatabaseFile.Filter = "Database Files(*.mdb)|*.mdb"
  196.     OpenDatabaseFile.Flags = OFN_FILEMUSTEXIST And OFN_PATHMUSTEXIST
  197.     OpenDatabaseFile.Action = 1
  198.  
  199.     'Close if cancelled
  200.     If Err = 32755 Then
  201.         Exit Sub
  202.     Else
  203.         DataBaseFile = OpenDatabaseFile.filename
  204.     End If
  205.      
  206.     Text1.Text = DataBaseFile
  207. End Sub
  208.  
  209. Private Sub cmdCancel_Click()
  210.      Unload NetworkDatabaseDemo
  211.      End
  212. End Sub
  213.  
  214. Private Sub cmdOK_Click()
  215.  
  216.    
  217.     Dim DataBaseFileOne As Integer
  218.     Dim DataBaseFileTwo As Integer
  219.  
  220.     Err = 0
  221.  
  222.     DataBaseFile = Text1.Text
  223.     
  224.     DataBaseFileOne = InStr(DataBaseFile, "NETBASE1.MDB")
  225.     DataBaseFileTwo = InStr(DataBaseFile, "NETBASE2.MDB")
  226.     
  227.     If Not DataBaseFileOne > 1 And DataBaseFileTwo = 0 Then
  228.     Err = 2
  229.     ElseIf Not DataBaseFileTwo > 1 And DataBaseFileOne = 0 Then
  230.     Err = 2
  231.     End If
  232.   
  233.     If Err = 1 Then
  234.         cmdOK.Enabled = False
  235.         MsgBox "File does not exist!", 48
  236.         Text1.SetFocus
  237.     End If
  238.     If Err = 2 Then
  239.         cmdOK.Enabled = False
  240.         MsgBox "This is an Invalid Database File!", 48
  241.         Text1.SetFocus
  242.     End If
  243.  
  244.     If Err = 0 Then
  245.         cmdOK.Enabled = False
  246.    
  247.         NetworkDatabaseDemo.WindowState = 1 ' iconize form
  248.         NetworkDatabaseDemo.Refresh
  249.  
  250.         'Build the chart
  251.         Call DrawNetChart(DataBaseFile)
  252.  
  253.         Call ValidateFilename
  254.     End If
  255.  
  256. End Sub
  257.  
  258. Private Sub DrawNetChart(DataBaseFile As String)
  259.         
  260.     Dim Shape As Object
  261.     Dim Shape1 As Object
  262.     Dim TextTitle As Object
  263.     Dim recCount As Integer
  264.     Dim PageWidth As Integer
  265.     Dim ChartCancelled As Integer
  266.     Dim CurrentRec As String
  267.     Dim FieldInfo As String
  268.     Dim ProcessorType As String
  269.     Dim Chart As Object
  270.     Dim ABCObject As Object
  271.     Dim NewLine() As Object
  272.     Dim Obj As Object
  273.     Dim DataBaseText As Object
  274.     Dim Counter As Integer
  275.     Dim TotalCount As Integer
  276.     
  277.     'Get the chart
  278.     Set Chart = ABC.New
  279.     
  280.     Rem Set the Chart's internal type
  281.     Chart.Type = "NETWORK"
  282.     Chart.TypeUsesEXE = True
  283.  
  284.     Set ABCObject = Chart.Objects
  285.  
  286.     'Prepare for chart to draw
  287.     Chart.NoRepaint = True
  288.     Chart.MasterItems.HideAll
  289.     Chart.PageLayout.Orientation = 1
  290.     Chart.View = 1
  291.     ABC.ShapePaletteVisible = False
  292.  
  293.     ' Set defaults so there are no shape numbers
  294.     Set Obj = Chart.DrawShape
  295.     Obj.Shape.NumberShowN = False
  296.     Chart.SetDefaults Obj
  297.     Obj.Clear_               'This object can be seen when selected'
  298.     
  299.     'Set gauge
  300.     ABC.PercentGauge NetworkDatabaseDemo.Caption, "Building Diagram", "Please Wait..."
  301.     ChartCancelled = ABC.PercentGaugeCancelled
  302.         If ChartCancelled = True Then
  303.         Call EndAppDraw
  304.         End If
  305.  
  306.     'Title page
  307.     Chart.CurrentShapePalette = "Standard"
  308.     Chart.CurrentShape = "Rounded Process"
  309.     Chart.DrawPositionX = 4.5
  310.     Chart.DrawPositionY = 0.5
  311.     Set Shape = Chart.DrawShape
  312.     Shape.Height = 0.5
  313.     Shape.Width = 5.5
  314.     Shape.Text = "Network Diagram"
  315.     Shape.Font.Size = 18
  316.     Shape.Font.Bold = True
  317.     Shape.Shape.BorderWidth = 3
  318.     Shape.Shape.BorderColor = ABC.RED
  319.     Shape.Shape.FillColor = ABC.GRAY
  320.  
  321.     'give feedback here
  322.     'ABC.PercentGaugeValue = 10
  323.  
  324.     'cancel chart?
  325.     ChartCancelled = ABC.PercentGaugeCancelled
  326.         If ChartCancelled Then
  327.         Call EndAppDraw
  328.         End If
  329.  
  330.    'Get Network palette
  331.     Chart.CurrentShapePalette = "Net - PC Workstations"
  332.     Chart.CurrentShape = "Tower"
  333.  
  334.     'Set shape spacing
  335.     Chart.DrawPositionX = 4.5
  336.     Chart.DrawPositionY = 1.5
  337.     
  338.     Set Shape1 = Chart.DrawShape
  339.     Shape1.Height = 1.25
  340.     Shape1.Width = 1.25
  341.     Shape1.Text = "SERVER"
  342.     Shape1.Font.Bold = True
  343.     Shape1.Font.Size = 12
  344.     
  345.     ChartCancelled = ABC.PercentGaugeCancelled
  346.         If ChartCancelled Then
  347.         Call EndAppDraw
  348.         End If
  349.   
  350.     'Open the Database
  351.     Data1.DatabaseName = DataBaseFile
  352.     Data1.RecordSource = "Network"
  353.     Data1.Refresh
  354.     
  355.     'Get the number of records
  356.     recCount = GetRecNum(Data1.Recordset)
  357.     Data1.Refresh
  358.  
  359.     PageWidth = Chart.PageLayout.Width
  360.  
  361.     If recCount <= 5 Then
  362.     Chart.DrawSpacingX = PageWidth / recCount
  363.     Chart.DrawPositionX = (PageWidth / 2) / recCount
  364.     Else
  365.     Chart.DrawSpacingX = 1.5
  366.     Chart.DrawPositionX = 1
  367.     End If
  368.  
  369.     Chart.DrawPositionY = 3.5
  370.     Chart.DrawDirection = 1
  371.  
  372.     Do While Not Data1.Recordset.EOF
  373.         CurrentRec = GetCurrRec(Data1.Recordset)
  374.         CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  375.         FieldInfo = Trim(NetSource.User)
  376.         ProcessorType = Trim(NetSource.Computer)
  377.  
  378.     'Draw Shapes and add Usernames
  379.         Chart.CurrentShape = ProcessorType
  380.         Set Shape = Chart.DrawShape
  381.         Shape.Height = 1.25
  382.         Shape.Width = 1.25
  383.         Shape.Text = FieldInfo
  384.         Shape.Font.Size = 12
  385.         Shape.Font.Color = ABC.BLUE
  386.  
  387.         TotalCount = recCount
  388.         Counter = 100 / TotalCount
  389.     
  390.  
  391.     'Draw Lines from server to workstation
  392.         Chart.CurrentLineRouting = 3
  393.  
  394.             ReDim NewLine(recCount) As Object
  395.  
  396.         Set NewLine(recCount) = Chart.DrawLine(Shape1, Shape, 2, 0)
  397.         NewLine(recCount).Line_.StemWidth = 3
  398.         recCount = recCount - 1
  399.  
  400.     'Increment gauge
  401.  
  402.         If Counter > 0 Then
  403.         ABC.PercentGaugeValue = Int(100 - (Counter * recCount))
  404.         End If
  405.         
  406.  
  407.  
  408.      Data1.Recordset.MoveNext
  409.     
  410.     Loop
  411.     
  412.     'Give feedback here
  413.     'ABC.PercentGaugeValue = 90
  414.  
  415.     ChartCancelled = ABC.PercentGaugeCancelled
  416.         If ChartCancelled Then
  417.         Call EndAppDraw
  418.         End If
  419.  
  420.     'Give double-click instructions
  421.     Chart.DrawPositionX = 1.5
  422.     Chart.DrawPositionY = 5
  423.     Set TextTitle = Chart.DrawTextBlock(UCase("To find server information, Double-click on a shape."))
  424.     TextTitle.Font.Bold = True
  425.     TextTitle.Font.Size = 16
  426.     TextTitle.CenterX = PageWidth / 2
  427.  
  428.     ' Write out database name
  429.     Chart.DrawPositionX = 1.5
  430.     Chart.DrawPositionY = 5.25
  431.     Set DataBaseText = Chart.DrawTextBlock(LCase(Text1))
  432.     DataBaseText.Font.Bold = False
  433.     DataBaseText.Font.Size = 12
  434.     DataBaseText.CenterX = PageWidth / 2
  435.     
  436.     'Data1.Recordset.Close
  437.     Data1.Refresh
  438.  
  439.     'Give feedback here
  440.     ABC.PercentGaugeValue = 99
  441.     ABC.HidePercentGauge
  442.     
  443.     'Draw chart
  444.     Chart.NoRepaint = False
  445.     Chart.Repaint
  446.     
  447.  
  448. End Sub
  449.  
  450. Private Sub EndAppDraw()
  451.         ABC.HidePercentGauge
  452.         End
  453. End Sub
  454.  
  455. Private Sub Form_Load()
  456.    'Open ABC
  457.     Set ABC = CreateObject("ABCFlow.Application")
  458.    ' ABC.Maximize
  459.     ABC.Hourglass = True
  460.     ABC.Visible = True
  461.  
  462.     'Register the Events
  463.     ABC.RegisterEvent ABC1, "Network", "DoubleClickSUBCLASS"
  464.     ABC.RegisterEvent ABC1, "Network", "AppQuitNOTIFY"
  465.     
  466.     'Load both forms
  467.     Load ServerInfo
  468.     NetworkDatabaseDemo.Left = (Screen.Width - Width) \ 2
  469.     NetworkDatabaseDemo.Top = (Screen.Height - Height) \ 2
  470.     Text1.Text = UCase(App.Path & "\" & "netbase1.mdb")
  471.     NetworkDatabaseDemo.Show
  472. End Sub
  473.  
  474. Private Sub GetDatabaseInfo(UserName As String)
  475.  
  476.     Dim CurrentRec As String
  477.  
  478.  
  479.     Data1.RecordSource = "Network"
  480.     Data1.Refresh
  481.     
  482.     'Find this username in the database
  483.         If UserName = Data1.Recordset.Fields("User").Value Then
  484.             CurrentRec = GetCurrRec(Data1.Recordset)
  485.             CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  486.  
  487.     'Display server information
  488.     ServerInfo.txtType.Text = Trim$(NetSource.Type)
  489.     ServerInfo.txtProcess = Trim$(NetSource.Computer)
  490.     ServerInfo.txtUserID = Trim$(NetSource.UserID)
  491.     ServerInfo.txtUserName = Trim$(NetSource.User)
  492.     ServerInfo.txtServer = Trim$(NetSource.Server)
  493.     ServerInfo.Show 1
  494.  
  495.           
  496.         ElseIf UserName = "" Then
  497.                     MsgBox "This Station is Unassigned.", 64
  498.         ElseIf Not UserName = Data1.Recordset.Fields("User").Value Then
  499.             Data1.Recordset.MoveFirst
  500.             Do
  501.                 Data1.Recordset.MoveNext
  502.                     On Error GoTo Error_out
  503.             Loop Until Data1.Recordset.EOF = True Or UserName = Data1.Recordset.Fields("User").Value
  504.                 CurrentRec = GetCurrRec(Data1.Recordset)
  505.                 CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  506.  
  507.     'Display server information
  508.     ServerInfo.txtType.Text = Trim$(NetSource.Type)
  509.     ServerInfo.txtProcess = Trim$(NetSource.Computer)
  510.     ServerInfo.txtUserID = Trim$(NetSource.UserID)
  511.     ServerInfo.txtUserName = Trim$(NetSource.User)
  512.     ServerInfo.txtServer = Trim$(NetSource.Server)
  513.     ServerInfo.Show 1
  514.         
  515.         End If
  516.  
  517. Error_out:
  518.           Select Case Err
  519.                 Case 3021
  520.             ServerInfo.Hide
  521.             MsgBox UCase("This is not a Workstation!") + Chr(13) + Chr(13) + "  Please choose a valid name."
  522.  
  523.             'DATA_ERRDISPLAY = 0
  524.             'DATA_ERRCONTINUE = 1
  525.             Data1.Refresh
  526.             Data1.Recordset.MoveFirst
  527.             Resume CloseDB
  528.                 Case Else
  529.                 Data1.Refresh
  530.                 ServerInfo.Hide
  531.           End Select
  532.  
  533. CloseDB:
  534.         Data1.Refresh
  535.         Data1.Recordset.MoveFirst
  536.         
  537. End Sub
  538.  
  539. Private Sub Text1_Change()
  540.     Call ValidateFilename
  541. End Sub
  542.  
  543. Private Sub Text1_GotFocus()
  544.  
  545.     Text1.SelStart = 0
  546.     Text1.SelLength = Len(Text1.Text)
  547.  
  548. End Sub
  549.  
  550. Private Sub ValidateFilename()
  551.     Dim Attr As Single
  552.  
  553.     On Error Resume Next
  554.  
  555.     Attr = GetAttr(Text1)
  556.     If Err Then
  557.         cmdOK.Enabled = False
  558.     Else
  559.         cmdOK.Enabled = True
  560.     End If
  561.     
  562. End Sub
  563.  
  564.